package com.fish.gaiety.gateway.entity;


import com.fish.gaiety.gateway.base.BaseApi;
import com.fish.gaiety.gateway.entity.dto.User;
import com.fish.gaiety.gateway.util.Gender;
import lombok.*;
import org.springframework.beans.BeanUtils;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import javax.validation.constraints.Email;

@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
@ToString(callSuper = true, exclude = "password")
public class UserApi extends BaseApi {

    private String name;

    private String firstName;

    private String nickName;

    @Email
    private String email;

    private Gender sex;

    @Getter(AccessLevel.NONE)
    private String password;

    private String phone;

    public User toUser(PasswordEncoder passwordEncoder){
        User user = new User();
        BeanUtils.copyProperties(this, user);
        user.setPassword(passwordEncoder.encode(this.password));
        return user;
    }

    public User toUser(){
        User user = new User();
        BeanUtils.copyProperties(this, user);
        user.setPassword(NoOpPasswordEncoder
                .getInstance()
                .encode(this.password));
        return user;
    }

    public UserApi (User user){
        BeanUtils.copyProperties(user, this);
    }

}
